{
  PootcherRoutines
  todo
}

unit PootcherRoutines;

interface

  uses
    Controls,
    Windows;

  var
    DoPatch : Boolean;

  function ExtractUrlFileName(const FullPath : WideString) : WideString;
  {procedure PCallback(CallbackMessage : WideString; Values : array of const); overload;
  procedure PCallback(CallbackMessage : WideString); overload;}
  procedure Download(const dURL, dDestination : WideString; Patch : Boolean);
  procedure DownloadFinished();
  procedure SetFormIcons(FormHandle: HWND; SmallIconName, LargeIconName: string);

implementation

//******************************************************************************
// Uses
//******************************************************************************
  uses
    SysUtils,
    Main,
    Messages;

//******************************************************************************
// Routines
//******************************************************************************
  (*
    ExtractUrlFilename
    todo
  *)
  function ExtractUrlFileName(const FullPath : WideString) : WideString;
  var
    LD : Integer;
  begin
    LD := LastDelimiter('/', FullPath);
    Result := Copy(FullPath, LD + 1, Length(FullPath) - LD);
  end; (*ExtractUrlFilename*)

  (*
    PCallback
    todo
  *)
  {procedure PCallback(CallbackMessage: WideString; Values: Array Of Const);
  var
    JoinedArray : TConstArray;
  begin
    try
      JoinedArray := JoinConstArrays([CallbackElement], Values);
      ExecJavascript(Format(CallbackMessage, JoinedArray));
    finally
      FinalizeConstArray(JoinedArray);
    end;
  end;} (*PCallback*)

  (*
    PCallback
    todo
  *)
  {procedure PCallback(CallbackMessage: WideString);
  begin
    if Closing = false then
      ExecJavascript(Format(CallbackMessage, [CallbackElement]));
  end;} (*PCallback*)

  (*
    Download
    todo
  *)
  procedure Download(const dURL, dDestination : WideString; Patch : Boolean);
  begin
    DoPatch := Patch;
  end; (*Download*)

  (*
    DownloadFinished
    todo
  *)
  procedure DownloadFinished();
  begin
    //if DoPatch = false then PCallback(PMESSAGE_SUCCESS);
  end; (*DownloadFinished*)

  procedure SetFormIcons(FormHandle: HWND; SmallIconName, LargeIconName: string);
  var
    hIconS, hIconL: Integer;
  begin
    hIconS := LoadIcon(hInstance, PChar(SmallIconName));
    if hIconS > 0 then begin
      hIconS := SendMessage(FormHandle, WM_SETICON, ICON_SMALL, hIconS);
      if hIconS > 0 then
        DestroyIcon(hIconS);
    end;
    hIconL := LoadIcon(hInstance, PChar(LargeIconName));
    if hIconL > 0 then begin
      hIconL := SendMessage(FormHandle, WM_SETICON, ICON_BIG, hIconL);
      if hIconL > 0 then
        DestroyIcon(hIconL);
    end;
  end;

end.
